﻿using System;
using System.IO;

[Serializable]
class ConnectionData
{    
    public string Pwd;
    public string Name;
    // 转成 byte[]
    public byte[] ToBytes()
    {
        using var ms = new MemoryStream();
        using var writer = new BinaryWriter(ms);
        
        writer.Write(Pwd);
        writer.Write(Name);

        return ms.ToArray();
    }

    // 从 byte[] 还原
    public static ConnectionData FromBytes(byte[] data)
    {
        using var ms = new MemoryStream(data);
        using var reader = new BinaryReader(ms);

        var obj = new ConnectionData
        {
            Pwd = reader.ReadString(),
            Name = reader.ReadString()
        };

        return obj;
    }
}
